package com.ll.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
 * 读取配置文件，并将配置文件中的变量添加到环境变量中
 * @author sunhuaili
 */
@Configuration
public class PropertyAutoConfiguration {
	
	
	@Bean
	public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		
		return PropertySourcesPlaceholderHandler.getInstance().getPropertySourcesPlaceholderConfigurer();
	}
	
	private static class PropertySourcesPlaceholderHandler{
		
		private static final PropertySourcesPlaceholderHandler instance = new PropertySourcesPlaceholderHandler();
		
		private PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer;
		
		private PropertySourcesPlaceholderHandler(){
			propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
			
			//可以在此实现，如何添加配置，以及配置的自动更新,以后实现集中化配置时，需要在此扩充代码
//			propertySourcesPlaceholderConfigurer.setProperties(properties);
		}
		
		public static final PropertySourcesPlaceholderHandler getInstance(){
			return instance;
		}
		
		public PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer(){
			return propertySourcesPlaceholderConfigurer;
		}
		
	}
}
